text = "Hello World, Welcome to Python World"

print("查找和替换:")
print(f"原始: '{text}'")                               # Hello World, Welcome to Python World
print(f"查找'World'位置: {text.find('World')}")        # 6 类似js的indexOf
print(f"查找'Python'位置: {text.find('Python')}")      # 24
print(f"查找不存在的: {text.find('Java')}")            # -1
print(f"从右边查找: {text.rfind('World')}")            # 31

print(f"索引查找: {text.index('World')}")              # 6
# print(text.index('Java'))  # 会抛出ValueError

print(f"出现次数: {text.count('World')}")              # 2
print(f"出现次数: {text.count('o')}")                  # 6

# 替换操作
print(f"替换: '{text.replace('World', 'Earth')}'")    # Hello Earth, Welcome to Python Earth
print(f"替换一次: '{text.replace('World', 'Earth', 1)}'") # Hello Earth, Welcome to Python World